package com.gold.util;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by zhusg <931583206@163.com>
 * 2015/8/19
 * 18:54
 * TO DO What
 */
public class DateUtil {

    /** 完整时间 yyyy-MM-dd HH:mm:ss */
    public static final String simple                  = "yyyy-MM-dd HH:mm:ss";

    /**
     * @Title:long2Time
     * @Description: 将long类型的时间值转换成标准格式的时间（yyyy-MM-dd HH:mm:ss）
     * @param createTime
     * @return
     * @return String
     */
    public static String long2Time(Long createTime) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
        String date = sdf.format(new Date(createTime*1000));
        return date;
    }

    /**
     * 获取系统当前日期(精确到毫秒)，格式：yyyy-MM-dd HH:mm:ss
     * @return
     */
    public  static String getDateFormatter(){
        Date date=new Date();
        DateFormat df=new SimpleDateFormat(simple);
        return df.format(date);
    }

    /**
     * 本月第一天
     * @return
     */
    public static String beginDate(){
        SimpleDateFormat formatter =  new SimpleDateFormat("yyyy-MM-dd");
        Calendar c = Calendar.getInstance();
        c.add(Calendar.MONTH, 0);
        //设置为1号,当前日期既为本月第一天
        c.set(Calendar.DAY_OF_MONTH,1);
        String beginDate = formatter.format(c.getTime());
        return beginDate;
    }

    /**
     * 本月当天
     * @return
     */
    public static String endDate(){
        Date date = new Date();
        SimpleDateFormat formatter =  new SimpleDateFormat("yyyy-MM-dd");
        String endDate  =  formatter.format(date);
        return endDate;
    }

    public static long timestamp(Long createTime) {
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
        Date date = new Date();
        //sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
        long epoch = date.parse("01/01/1970 01:00:00");
        return epoch;
    }

    public static void main(String[] arg){
        System.out.println(long2Time(Long.parseLong("1442047122")));


        //long epoch = new Date().parse("01/01/1970 01:00:00");
        //System.out.println(epoch);

        //1、取得本地时间：
        /*final java.util.Calendar cal = java.util.Calendar.getInstance();
        System.out.println(cal.getTime());
        //2、取得时间偏移量：
        final int zoneOffset = cal.get(java.util.Calendar.ZONE_OFFSET);
        System.out.println(zoneOffset);
        //3、取得夏令时差：
        final int dstOffset = cal.get(java.util.Calendar.DST_OFFSET);
        System.out.println(dstOffset);
        //4、从本地时间里扣除这些差量，即可以取得UTC时间：
        cal.add(java.util.Calendar.MILLISECOND, -(zoneOffset + dstOffset));
        System.err.println(cal.getTime());


        java.util.TimeZone zone = java.util.TimeZone.getTimeZone("UTC");
        java.util.Calendar calendar = java.util.Calendar.getInstance(zone);

        System.out.println(calendar.getTimeInMillis()/1000);*/

    }

}
